package com.twu.biblioteca.books;

import java.util.ArrayList;
import java.util.List;

public class BookCollection {

    private List<Book> books;
    private static BookCollection collection;

    public static BookCollection getInstance() {
        if (collection == null) {
            collection = new BookCollection();
        }
        return collection;
    }

    private BookCollection() {
        books = new ArrayList<Book>();
        books.add(new Book("How To Cheat At A ThoughtWorks Assignment", "1234"));
        books.add(new Book("Refactoring", "5678"));
        books.add(new Book("TDD By Example", "4321"));
        books.add(new Book("Head First Design Patterns", "2341"));
    }

    public Book checkOut(String isbnNumber) {
        for (Book book : books) {
            if (book.compareISBNWith(isbnNumber))
                return book;
        }
        return null;
    }

    public List<Book> getAll() {
        return books;
    }
}